package com.mmlc.meimei.lichengkongjian.been;

import com.mmlc.network.responsebean.OrderListResponseBean;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/7/20 0020.
 */
public class AllOrderBean implements Cloneable {
    /**
     * "cancel":0, //取消订单
     * "go_pay":1, //去支付
     * "confirm":0, //确认收货
     * "comment":0, //评价晒单
     * "sale_after":0, //申请售后
     * "buy_again":0//再次购买
     */
    public String photoUrl;
    public String orderNumber;//订单编号
    public String shopInfo;//商品信息
    public String shopColor;//商品颜色
    public String shopPrice;//单件商品价格
    public String allShopCount;//多件商品的总价格
    public String shopCount;//商品数量
    public int type = 1;//1-单个订单，2-多个订单
    public String orderStatus;//订单状态

    public OrderListResponseBean data;
    public List<Integer> orderButtonType;//对外提供的
    public List<AllOrderBean> orderList;//每个订单号下的商品信息都放在这里

    public void setData(OrderListResponseBean data) {
        this.data = data;
        //计算有几种类型的Button
        orderButtonType = calcButtonType(data);

    }

    private List<Integer> calcButtonType(OrderListResponseBean data) {
        List<Integer> orderButtonType = new ArrayList<Integer>();
        for (int i = 0; i < data.getData().size(); i++) {
            OrderListResponseBean.DataBean.OperBean oper = data.getData().get(i).getOper();

            if (oper.getCancel() == 1) {//取消订单 type = 1;
                orderButtonType.add(1);
            } else if (oper.getGo_pay() == 1) {//去支付 type = 2;
                orderButtonType.add(2);
            } else if (oper.getConfirm() == 1) {//确认收货 type = 3;
                orderButtonType.add(3);
            } else if (oper.getComment() == 1) {//评价晒单 type = 4
                orderButtonType.add(4);
            } else if (oper.getSale_after() == 1) {//申请售后 type = 5
                orderButtonType.add(5);
            } else if (oper.getBuy_again() == 1) {//再次购买 type = 6
                orderButtonType.add(6);
            }
        }
        return orderButtonType;
    }

    public AllOrderBean addPrefix() {
        AllOrderBean bean = null;
        try {
            bean = (AllOrderBean) this.clone();
            bean.orderNumber = "订单编号: " + this.orderNumber;
            bean.shopColor = "颜色: " + this.shopColor;
            bean.shopPrice = "¥ " + this.shopPrice;
            bean.shopCount = "X " + this.shopCount;
        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
        }
        return bean;
    }
}
